<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>


  
  
  <meta content="text/html; charset=ISO-8859-1" http-equiv="content-type">


  
  
  <title>About securityimages</title>
</head>


<body>


<table style="text-align: left; width: 1158px;" border="0" cellpadding="2" cellspacing="2">


  <tbody>


    <tr>


      <td style="width: 359px;"><a href="http://www.waltercedric.com" target="_new"><img style="width: 372px; height: 362px;" alt="" src="components/com_securityimages/logo/com_securityimages.jpg" border="0"></a></td>


      <td style="width: 779px;">
      
      
      <h1><small><b>Using SecurityImages framework in Your code</b></small></h1>
      <span style="font-weight: bold;">
This page is dedicated to any 3rd party developer of Joomla! 1.5&nbsp; which want to use SecurityImages component in their code.</span><br>

      <br>
Lets take the <strong>contact section</strong> of Joomla! 1.5 as&nbsp; an example. <span style="font-family: Arial Black; color: rgb(255, 0, 0);"></span>
      <p><span style="font-family: monospace;">I</span>t is always
recommended to use a switch in all your component to activate
deactivate SecurityImages per components&nbsp; through the administrator
control panel. </p>
  
      <p>This is done by adding to <font face="Courier New">administrator/components/com_contact/contact_items.xml </font>the following code:     <br>
    </p>
  
      <div style="margin: 5px 20px 20px;">   
      <pre class="alt2" style="border: 1px inset ; margin: 0px; padding: 6px; overflow: auto; width: 640px; height: 82px; text-align: left;">&lt;param name="useSecurityImages" type="radio" default="1" label="Use SecurityImage Captcha" description="Enable Captcha verification"&gt;<br>            &lt;option value="0"&gt;No&lt;/option&gt;<br>            &lt;option value="1"&gt;Yes&lt;/option&gt;<br>&lt;/param&gt;</pre>
 </div>
  
      <p>Joomla will read this xml file on the fly&nbsp; and build the graphical user interface for the contact settings.</p>
  
      <p><a href="http://www.waltercedric.com/images/stories/ContactsectionofJoomla1.5usingsecurity.0_EF9B/contact.settings.securityimages.5.0.gif"><img src="http://www.waltercedric.com/images/stories/ContactsectionofJoomla1.5usingsecurity.0_EF9B/contact.settings.securityimages.5.0_thumb.gif" alt="contact.settings.securityimages.5.0" border="0" height="151" width="287"></a> </p>
  
      <p>Since Joomla! 1.5 now use a Model View Controller paradigm, we have to alter the controller, and add a new Task <font color="#000000"><font color="#0000bb">displaySecurityImagesCaptcha</font><font color="#007700">()</font></font>in&nbsp; <span style="font-family: courier new,courier,monospace;">components/com_contact/controller.php:</span>     <br>
    </p>
  
      <div style="margin: 5px 20px 20px;">   
      <div class="alt2" style="border: 1px inset ; margin: 0px; padding: 6px; overflow: auto; width: 640px; height: 322px; text-align: left;" dir="ltr"><!-- php buffer start --><font color="#000000"><font color="#0000bb">&nbsp;&nbsp; </font><font color="#007700">function </font><font color="#0000bb">displaySecurityImagesCaptcha</font><font color="#007700">() {&nbsp; <br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; global </font><font color="#0000bb">$mainframe</font><font color="#007700">;&nbsp; <br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //Per contact you can define if the user has to resolve the capctha&nbsp; <br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </font><font color="#0000bb">$contactId </font><font color="#007700">= </font><font color="#0000bb">JRequest</font><font color="#007700">::</font><font color="#0000bb">getVar</font><font color="#007700">(</font><font color="#dd0000">'contact_id'</font><font color="#007700">, </font><font color="#0000bb">0</font><font color="#007700">, </font><font color="#dd0000">''</font><font color="#007700">, </font><font color="#dd0000">'int'</font><font color="#007700">);&nbsp; <br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </font><font color="#ff8000">// load the contact details&nbsp; <br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </font><font color="#0000bb">$model&nbsp;&nbsp;&nbsp; </font><font color="#007700">= &amp;</font><font color="#0000bb">$this</font><font color="#007700">-&gt;</font><font color="#0000bb">getModel</font><font color="#007700">(</font><font color="#dd0000">'contact'</font><font color="#007700">);&nbsp; <br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </font><font color="#0000bb">$qOptions</font><font color="#007700">[</font><font color="#dd0000">'id'</font><font color="#007700">] = </font><font color="#0000bb">$contactId</font><font color="#007700">;&nbsp; <br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </font><font color="#0000bb">$contact&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </font><font color="#007700">= </font><font color="#0000bb">$model</font><font color="#007700">-&gt;</font><font color="#0000bb">getContact</font><font color="#007700">( </font><font color="#0000bb">$qOptions </font><font color="#007700">);&nbsp; <br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </font><font color="#0000bb">$params </font><font color="#007700">= new </font><font color="#0000bb">JParameter</font><font color="#007700">( </font><font color="#0000bb">$contact</font><font color="#007700">-&gt;</font><font color="#0000bb">params </font><font color="#007700">);&nbsp; <br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (</font><font color="#0000bb">$params</font><font color="#007700">-&gt;</font><font color="#0000bb">get</font><font color="#007700">(</font><font color="#dd0000">'useSecurityImages'</font><font color="#007700">)) {&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </font><font color="#0000bb">$check </font><font color="#007700">= </font><font color="#0000bb">null</font><font color="#007700">;&nbsp; <br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </font><font color="#0000bb">$mainframe</font><font color="#007700">-&gt;</font><font color="#0000bb">triggerEvent</font><font color="#007700">(</font><font color="#dd0000">'</font></font><font color="#000000"><font color="#dd0000">onSecurityImagesDisplay</font></font><font color="#000000"><font color="#dd0000">'</font><font color="#007700">, array(</font><font color="#0000bb">$</font></font><font color="#000000"><font color="#0000bb">check</font></font><font color="#000000"><font color="#007700">));&nbsp; <br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (!</font><font color="#0000bb">$</font></font><font color="#000000"><font color="#0000bb">check</font></font><font color="#000000"><font color="#007700">) {&nbsp; <br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; echo </font><font color="#dd0000">"&lt;br/&gt;Erreur affichage du Captcha&lt;br/&gt;"</font><font color="#007700">;&nbsp; <br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }&nbsp; <br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }&nbsp; <br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br>
&nbsp;&nbsp;&nbsp; }&nbsp; <br>
      </font></font><!-- php buffer end --></div>
 </div>

As you can see, the event "onSecurityImagesDisplay" is triggered on a
per contact name basis. That mean that some contact can have a Captcha
while other have not.&nbsp; <br>
  <br>
The next step is to add the task checkSecurityImagesCaptcha() checking the captcha in the <span style="font-family: courier new,courier,monospace;">components/com_contact/controller.php</span>   <br>
  
      <div style="margin: 5px 20px 20px;">       
      <div class="alt2" style="border: 1px inset ; margin: 0px; padding: 6px; overflow: auto; width: 640px; height: 354px; text-align: left;" dir="ltr"><!-- php buffer start --><font color="#000000"><font color="#007700">function </font><font color="#0000bb">checkSecurityImagesCaptcha</font><font color="#007700">() {&nbsp; <br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; global </font><font color="#0000bb">$mainframe</font><font color="#007700">;&nbsp; <br>
&nbsp;&nbsp; <br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </font><font color="#0000bb">$contactId </font><font color="#007700">= </font><font color="#0000bb">JRequest</font><font color="#007700">::</font><font color="#0000bb">getVar</font><font color="#007700">(</font><font color="#dd0000">'id'</font><font color="#007700">, </font><font color="#0000bb">0</font><font color="#007700">, </font><font color="#dd0000">''</font><font color="#007700">, </font><font color="#dd0000">'int'</font><font color="#007700">);&nbsp; <br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </font><font color="#ff8000">// load the contact details&nbsp; <br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </font><font color="#0000bb">$model&nbsp;&nbsp;&nbsp; </font><font color="#007700">= &amp;</font><font color="#0000bb">$this</font><font color="#007700">-&gt;</font><font color="#0000bb">getModel</font><font color="#007700">(</font><font color="#dd0000">'contact'</font><font color="#007700">);&nbsp; <br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </font><font color="#0000bb">$qOptions</font><font color="#007700">[</font><font color="#dd0000">'id'</font><font color="#007700">] = </font><font color="#0000bb">$contactId</font><font color="#007700">;&nbsp; <br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </font><font color="#0000bb">$contact&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </font><font color="#007700">= </font><font color="#0000bb">$model</font><font color="#007700">-&gt;</font><font color="#0000bb">getContact</font><font color="#007700">( </font><font color="#0000bb">$qOptions </font><font color="#007700">);&nbsp; <br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </font><font color="#0000bb">$params </font><font color="#007700">= new </font><font color="#0000bb">JParameter</font><font color="#007700">( </font><font color="#0000bb">$contact</font><font color="#007700">-&gt;</font><font color="#0000bb">params </font><font color="#007700">);&nbsp; <br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //check if that user has a capctha&nbsp; <br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </font><font color="#007700">if (!</font><font color="#0000bb">$params</font><font color="#007700">-&gt;</font><font color="#0000bb">get</font><font color="#007700">(</font><font color="#dd0000">'</font></font><font color="#000000"><font color="#dd0000">useSecurityImages</font></font><font color="#000000"><font color="#dd0000">'</font><font color="#007700">)) {&nbsp;&nbsp; <br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return </font><font color="#0000bb">true</font><font color="#007700">;&nbsp; <br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }&nbsp; <br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </font><font color="#0000bb">$return </font><font color="#007700">= </font><font color="#0000bb">false</font><font color="#007700">;&nbsp; <br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </font><font color="#0000bb">$securityImagesJoomlaContactUserTry </font><font color="#007700">= </font><font color="#0000bb">JRequest</font><font color="#007700">::</font><font color="#0000bb">getVar</font><font color="#007700">(</font><font color="#dd0000">'securityImagesJoomlaContactUserTry'</font><font color="#007700">, </font><font color="#0000bb">false</font><font color="#007700">, </font><font color="#dd0000">''</font><font color="#007700">, </font><font color="#dd0000">'CMD'</font><font color="#007700">);&nbsp; <br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </font><font color="#0000bb">$mainframe</font><font color="#007700">-&gt;</font><font color="#0000bb">triggerEvent</font><font color="#007700">(</font><font color="#dd0000">'</font></font><font color="#000000"><font color="#dd0000">onSecurityImagesCheck</font></font><font color="#000000"><font color="#dd0000">'</font><font color="#007700">, array(</font></font><font color="#000000"><font color="#0000bb">$securityImagesJoomlaContactUserTry</font></font><font color="#000000"><font color="#007700"> &amp;</font><font color="#0000bb">$return</font><font color="#007700">));              <br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return </font></font><font color="#000000"><font color="#0000bb">$return;</font></font><font color="#000000"><font color="#007700">              <br>
&nbsp;&nbsp;&nbsp; }&nbsp; <br>
      </font></font><!-- php buffer end --></div>
 </div>
 One more step is to alter the original submit() method of the controller in <span style="font-family: courier new,courier,monospace;">components/com_contact/controller.php</span>   
      <div style="margin: 5px 20px 20px;">   
      <div class="alt2" style="border: 1px inset ; margin: 0px; padding: 6px; overflow: auto; width: 640px; height: 146px; text-align: left;" dir="ltr"><!-- php buffer start -->&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <font color="#000000"><font color="#007700">global </font><font color="#0000bb">$mainframe</font><font color="#007700">;&nbsp; </font></font><font color="#000000"><font color="#ff8000">&nbsp;&nbsp; <br>
              <br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </font><font color="#007700">if (!</font><font color="#0000bb">$this</font><font color="#007700">-&gt;</font></font><font color="#000000"><font color="#0000bb">checkSecurityImagesCaptcha</font><font color="#007700">()</font></font><font color="#000000"><font color="#007700">) {              <br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </font><font color="#0000bb">JError</font><font color="#007700">::</font><font color="#0000bb">raiseWarning</font><font color="#007700">(</font><font color="#dd0000">"999"</font><font color="#007700">,</font><font color="#007700">"Invalid Captcha Code");              <br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </font><font color="#0000bb">$this</font><font color="#007700">-&gt;</font><font color="#0000bb">display</font><font color="#007700">();              <br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return </font><font color="#0000bb">false</font><font color="#007700">;              <br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }&nbsp; <br>
      </font></font><!-- php buffer end --></div>
 </div>
 And finally altering the view <span style="font-family: courier new,courier,monospace;">/com_contact/views/contact/tmpl/default_form.php    <br>
      <span style="font-family: times new roman,times,serif;">to display the Captcha field</span>     <br>
      </span>  <br>
  
      <div style="margin: 5px 20px 20px;">   
      <div class="alt2" style="border: 1px inset ; margin: 0px; padding: 6px; overflow: auto; width: 640px; height: 130px; text-align: left;" dir="ltr"><font color="#000000"><font color="#0000bb">&lt;?php </font><font color="#007700">if (</font><font color="#0000bb">$this</font><font color="#007700">-&gt;</font><font color="#0000bb">params</font><font color="#007700">-&gt;</font><font color="#0000bb">get</font><font color="#007700">(</font><font color="#dd0000">'</font></font><font color="#000000"><font color="#dd0000">useSecurityImages</font></font><font color="#000000"><font color="#dd0000">'</font><font color="#007700">)) { </font><font color="#0000bb">?&gt;</font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br>
&lt;img src="/index.php?option=com_contact&amp;task=</font><font color="#000000"><font color="#0000bb">displaySecurityImagesCaptcha</font></font><font color="#000000">&amp;contact_id=<font color="#0000bb">&lt;?php </font><font color="#007700">echo </font><font color="#0000bb">$this</font><font color="#007700">-&gt;</font><font color="#0000bb">contact</font><font color="#007700">-&gt;</font><font color="#0000bb">id</font><font color="#007700">; </font><font color="#0000bb">?&gt;</font>"&gt;&nbsp; <br>
&lt;br /&gt;&nbsp; <br>
&lt;input type="text" name="securityImagesJoomlaContactUserTry" /&gt;&nbsp; <br>
&lt;br /&gt;&nbsp; <br>
&nbsp;<font color="#0000bb">&lt;?php </font><font color="#007700">} </font><font color="#0000bb">?&gt;</font> </font><!-- php buffer end --></div>
 </div>
 As you see a lot of thing have been done, and I am still testing and improving the code.
			
      <br>

      <span style="color: rgb(255, 0, 0); font-family: Arial Black;">Final Notes</span><br>

      
      <ul>

        <li>Securityimages component can be put in debug mode or be deactivated site wide.</li>

        <li>If is recommended to have a switch in your code to enable
disable usage of securityimages in case the user hasn't installed it
yet.</li>

      
      </ul>

      <br>

      <span style="font-weight: bold;">Have fun...</span><br>

      <br>

      <br>

      <br>

      <br>

      <br>

      <br>

      <br>

      <br>

      <br>

      <br>

      <br>

      <br>

      <br>

      <br>

      <br>

      <br>

      </td>

    </tr>

  
  </tbody>
</table>

<br>


</body>
</html>
